﻿using System;
using ZX.Web.UI.Controls;
using ZX.CRM.Bussiness;
using System.Data;

namespace ZX.WebApp.DeskTop.DeskTopItem
{
    public partial class MessageReport : BasePage
    {
        int dataType = 0;
        BCrmReport BReport = new BCrmReport();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["dataType"] == null || Request["dataType"] == "")
                dataType = 0;
            else
                dataType = int.Parse(Request["dataType"]);
            getdt(dataType);
        }

        private int getPowerType
        {
            get
            {
                int powertype = 0;
                if (Request["PowerType"] == null || Request["PowerType"] == "" || Request["PowerType"] == "0")
                    powertype = 0;
                else
                    powertype = 1;
                return powertype;
            }
        }
        private string Obj
        {
            get
            {
                string obj = Request["obj"];
                return obj;
            }
        }
        private string url
        {
            get
            {
                string url = Request["url"];
                return url;
            }
        }

        /// <summary>
        /// type   0：昨日、1：本周、2：月份、3：季度、4：本年
        /// </summary>
        /// <param name="type"></param>
        public void getdt(int type)
        {
            var htmlTemp = "";
            var pageType = Request["pageType"];
            htmlTemp += "<div><a onclick=\"GetReportData('" + url + "','" + Obj + "','" + pageType + "',0)\" href=\"javascript:void(0)\">昨日</a>/";
            htmlTemp += "<a onclick=\"GetReportData('" + url + "','" + Obj + "','" + pageType + "',1)\" href=\"javascript:void(0)\">本周</a>/";
            htmlTemp += "<a onclick=\"GetReportData('" + url + "','" + Obj + "','" + pageType + "',2)\" href=\"javascript:void(0)\">月份</a>/";
            htmlTemp += "<a onclick=\"GetReportData('" + url + "','" + Obj + "','" + pageType + "',3)\" href=\"javascript:void(0)\">季度</a>/";
            htmlTemp += "<a onclick=\"GetReportData('" + url + "','" + Obj + "','" + pageType + "',4)\" href=\"javascript:void(0)\">本年</a></div>";
            htmlTemp += "<div style='width:100%;height:90%;overflow:auto;'><table class='tableContent' cellspacing='0'>";
            htmlTemp += "<tr>";
            htmlTemp += "    <th style='width:40%;border-left:1px solid #C1DAD7;'>类别</th>";
            htmlTemp += "    <th style='width:30%;'>总数</th>";
            htmlTemp += "    <th style='width:30%;'>目标</th>";
            htmlTemp += " </tr>";
            DataTable myDataTable = new DataTable();
            myDataTable = BReport.ReturnMessageReport(new Guid(this.UserId.ToString()), type, getPowerType);

            if (myDataTable.Rows.Count > 0)
            {
                string[] tempData = { "录入客户总数", "约场总数", "讲场总数", "成交场", "成交执模人数", "成交未回款", "成交已回款" };
                int i = 0;
                foreach (DataRow row in myDataTable.Rows)
                {
                    htmlTemp += "<tr><td style='border-left:1px solid #C1DAD7;'>" + tempData[i] + "</td>";
                    switch (i)
                    {
                        case 0: htmlTemp += "<td style='color:Blue;'>" + row["录入客户总数"].ToString() + "</td>"; break;
                        case 1: htmlTemp += "<td style='color:Blue;'>" + row["约场总数"].ToString() + "</td>"; break;
                        case 2: htmlTemp += "<td style='color:Blue;'>" + row["讲场总数"].ToString() + "</td>"; break;
                        case 3: htmlTemp += "<td style='color:Blue;'>" + row["成交场"].ToString() + "</td>"; break;
                        case 4: htmlTemp += "<td style='color:Blue;'>" + row["成交执模人数"].ToString() + "</td>"; break;
                        case 5: htmlTemp += "<td style='color:Blue;'>" + row["成交未回款"].ToString() + "</td>"; break;
                        case 6: htmlTemp += "<td style='color:Blue;'>" + row["成交已回款"].ToString() + "</td>"; break;
                    }
                    htmlTemp += "<td style='color:Blue;'>......</td></tr>";

                    htmlTemp += "<tr><td style='border-left:1px solid #C1DAD7;'>" + row["Caption"].ToString() + "</td>";
                    htmlTemp += "<td>" + row["未交付"].ToString() + "</td>";
                    htmlTemp += "<td>" + row["交付中"].ToString() + "</td>";
                    htmlTemp += "<td>" + row["已交付"].ToString() + "</td></tr>";
                    i++;
                }
            }
            else
            {
                htmlTemp += "<tr><td colspan='7' style='border-left:1px solid #C1DAD7;'>没有数据...</td></tr>";
            }
            htmlTemp += " </table></div>";
            Response.Clear();
            Response.ContentType = "application/json";
            Response.Write(htmlTemp);
            Response.End();
        }
    }
}